﻿using System;
using System.Linq;
using System.Collections.Generic;
using Shell.DomainDot;
using Framework.Poco;

namespace Framework.Domain
{
    /// <summary>
    /// 图片上下文
    /// </summary>
    public class PictureContext : DomainDotBase<PictureCategory>
    {
        /// <summary>
        /// 属于分类的所有图片
        /// </summary>
        public WithMany<BinaryFile> Pictures { private get; set; }

        /// <summary>
        /// 获取所有属于分类的图片
        /// </summary>
        public IEnumerable<BinaryFile> GetAll()
        {
            return this.Pictures;
        }

        /// <summary>
        /// 绑定文件
        /// </summary>
        public void BindBinaryFile(List<Guid> identities)
        {
            foreach (var item in identities)
            {
                this.Pictures.Bind(item);
                this.Pictures.Submit();
            }
        }

        /// <summary>
        /// 修改文件
        /// </summary>
        public void Edit(Guid identity, int rank, string description)
        {
            var original = this.GetAll().SingleOrDefault(o => o.Id.Equals(identity));
            if (original != null)
            {
                original.Rank = rank;
                original.Description = description;
                this.Pictures.Submit();
            }
        }

        /// <summary>
        /// 删除文件
        /// </summary>
        public void Delete(Guid identity)
        {

            this.Pictures.Delete(identity);
            this.Pictures.Submit();
        }
    }
}
